package me.sdevil507.org.mapper;

import me.sdevil507.org.dto.OrgDeptParamsDto;
import me.sdevil507.org.dto.OrgDeptResultDto;
import me.sdevil507.org.dto.OrgDeptSimpleResultDto;
import me.sdevil507.org.po.OrgDeptPo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 机构部门表[OrgDeptMapper]
 *
 * @author sdevil507
 * created on 2020-06-24 14:29:16
 */
@Component
@Mapper(componentModel = "spring", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface OrgDeptMapper {

    /**
     * po => dto
     *
     * @param po 实体类
     * @return dto传输类
     */
    @Mapping(source = "org.id", target = "orgId")
    @Mapping(source = "org.shortNameZh", target = "orgName")
    OrgDeptResultDto po2dto(OrgDeptPo po);

    /**
     * po => simpleDto
     *
     * @param po 实体类
     * @return dto传输类
     */
    @Mapping(source = "org.id", target = "orgId")
    @Mapping(source = "org.shortNameZh", target = "orgName")
    OrgDeptSimpleResultDto po2SimpleDto(OrgDeptPo po);

    /**
     * pos => dtos
     *
     * @param pos 实体类集合
     * @return dtos传输类集合
     */
    List<OrgDeptResultDto> pos2dtos(List<OrgDeptPo> pos);

    /**
     * pos => simpleDtos
     *
     * @param pos 实体类集合
     * @return dtos传输类集合
     */
    List<OrgDeptSimpleResultDto> pos2SimpleDtos(List<OrgDeptPo> pos);

    /**
     * dto => po
     *
     * @param dto 传输类
     * @return po实体类
     */
    @Mapping(source = "orgId", target = "org.id")
    OrgDeptPo dto2po(OrgDeptParamsDto dto);

    /**
     * dtos => pos
     *
     * @param dtos 传输类集合
     * @return pos实体类集合
     */
    List<OrgDeptPo> dtos2pos(List<OrgDeptParamsDto> dtos);

    /**
     * 使用dto更新po
     *
     * @param dto 传输类
     * @param po  实体类
     */
    void updatePoFromDto(OrgDeptParamsDto dto, @MappingTarget OrgDeptPo po);
}